layui.use(['jquery','element','table'],function() {
    var $ = layui.$, page = layui.laypage;

    /**
     * 订单管理初始化
     */
    var Order = {
        layerIndex: -1
    };
    /**
     * 初始化layui分页
     */

    Order.initLayPage = function () {
        var state = ''
        var pageConf = {
            limit: 10,
            offset: 1,
            state:state,
            orderid:orderid
        };
        $.post("/order/list/", pageConf, function (data) {

            page.render({
                elem: 'laypage',
                count: data.total,
                curr: pageConf.offset,
                limit: pageConf.limit,
                first: "首页",
                last: "尾页",
                layout: ['count', 'prev', 'page', 'next', 'limit', 'skip'],
                jump: function (obj, first) {
                    if (!first) {
                        pageConf.offset = (obj.curr-1)*10;
                        pageConf.limit = obj.limit;
                        $.post("/order/list/", pageConf, function (data) {
                            Order.fillTable(data.rows);
                        });

                    }
                }
            });
            Order.fillTable(data.rows);
        });

    }


    Order.reinitIframe = function(){
        var J_iframe = self.parent.document.getElementsByClassName("J_iframe")[0];
        try{
            var bHeight = J_iframe.contentWindow.document.body.scrollHeight;
            var dHeight = J_iframe.contentWindow.document.documentElement.scrollHeight;
            var height = Math.max(bHeight, dHeight);
            J_iframe.height = height;
        }catch (ex){
            console.log(ex)
        }
    }
//填充表格数据
    Order.fillTable = function (data) {
        $("#list-cont").empty();
        $.each(data, function (index, obj) {
            var orderMerStr = '';
            orderMerStr += '<ul class="item-content layui-clear">\n'+
                '                <li class="th th-id">\n' +
                '                <span class="id" >' + obj.id + '</span>\n' +
                '                </li>\n';
            var data1 = obj.orderMerList;
            var mertable = '<table style="float:left"><tbody>'
            $.each(data1, function (index, items) {
                var merattrStr = '';
                $.each(items.merattr, function (index, item) {
                    merattrStr += '<span>' + item + '</span>&nbsp&nbsp\n'
                })
                mertable += '<tr><td><li class="th th-item">\n' +
                    '                <div class="item-cont">\n' +
                    '                <a href="javascript:;"><img src="/kaptcha/' + items.merpictureurl + '" alt=""></a>\n' +
                    '                <div class="text">\n' +
                    '                <div class="title">' + items.mername + '</div>\n' +
                    '                <p>\n' + merattrStr +
                    '            </div>\n' +
                    '            </div>\n' +
                    '            </li>\n</td>' +
                    '            <td><li class="th th-price">\n' +
                    '                <span class="th-su">' + items.merprice + '</span>\n' +
                    '                </li>\n</td>' +
                    '                <td><li class="th th-amount">\n' + items.merquantity +
                    '                </li>\n</td>';

            });
            mertable += '</tbody></table>';
            orderMerStr += mertable;
            orderMerStr += '<li class="th th-sum">\n' +
                '                <span class="sum">' + obj.sumprice + '</span>\n' +
                '                </li>\n' +
                '                </ul>';
            $("#list-cont").append(orderMerStr);

        });
        Order.reinitIframe();
    }


    Order.initLayPage();
    $(".pay").on('click',function(){
        window.location.href = '/order/pay?orderid='+orderid;
    })


})

